Recent Questions

ساخت وبلاگ
If you need to set an environment to be a specific one such as staging you can override the environment by changing the config value app_env config(['app.env' => 'staging']); Then doing a dd on config(‘app.env’) will retu that environment you’ve just set. I haven’t found a way to set environments with app()->environment() so instead, I recommend using this in_array function and passing in the config(‘app.env’) and then specifically defining the environments.  in_array(config('app.env'), ['local', 'staging']) For example, say you have this in a command: if (! in_array(config('app.env'), ['local', 'staging'])) { $this->error(‘Will only run on local and staging environments’); retu true; } Test this runs when the environment is set to production test(‘cannot run on production’, function () { config(['app.env' => 'production']); $this->artisan('db:production-sync') ->expectsOutput(‘DB sync will only run on local and staging environments’) ->assertExitCode(true); }); Recent Questions...
ما را در سایت Recent Questions دنبال می کنید

برچسب : نویسنده : استخدام کار superuser بازدید : 260 تاريخ : چهارشنبه 22 تير 1401 ساعت: 15:59

When a project grows the migrations folder can contain a lot of migration, ever wanted to desperate them into folders? tus out it's easy to so. All you need to do is tell Laravel where to read the migrations from. In your AppServiceProvider.php boot call, you can call $this->loadMigrationsFrom() and give it a path of all the folder locations: $migrationsPath = database_path('migrations'); $directories = glob($migrationsPath.'/*', GLOB_ONLYDIR); $paths = array_merge([$migrationsPath], $directories); $this->loadMigrationsFrom($paths); Now when you run php artisan migrate all folders will be scanned. To migrate specific folders use --path for example for all migration in a folder called posts php artisan migrate --path=/database/migrations/posts or to make migration in a folder: php artisan make:migration create_posts_table --path=/database/migrations/posts Recent Questions...
ما را در سایت Recent Questions دنبال می کنید

برچسب : نویسنده : استخدام کار superuser بازدید : 177 تاريخ : چهارشنبه 22 تير 1401 ساعت: 15:59

When you have a CSV generated how do you test it runs. Take this extract: public function export() { $actions = $this->getData()->get(); $columns = [ 'User', 'Start Date', 'End Date', ]; $data = []; foreach ($actions as $action) { $data[] = [ $action->user->name ?? '', $action->due_at, $action->completed_at, ]; } $now = Carbon::now()->format('d-m-Y'); $filename = "actions-{$now}"; retu csv_file($columns, $data, $filename); } The above collects data and sends it to a helper function called csv_file which in tu will export a CSV file. For completeness it contains: if (! function_exists('csv_file')) { function csv_file($columns, $data, string $filename = 'export'): BinaryFileResponse { $file = fopen('php://memory', 'wb'); $csvHeader = [...$columns]; fputcsv($file, $csvHeader); foreach ($data as $line) { fputcsv($file, $line); } fseek($file, 0); $uid = unique_id(); Storage::disk('local')->put("public/$uid", $file); retu response()->download(storage_path('app/public/'.$uid), "$filename.csv")->deleteFileAfterSend(true); } } Now there are 2 tests I want to confirm first, I get 200 status response to ensure the endpoint does not throw an error and secondly, the response contains the generated file name for Recent Questions...
ما را در سایت Recent Questions دنبال می کنید

برچسب : نویسنده : استخدام کار superuser بازدید : 211 تاريخ : چهارشنبه 22 تير 1401 ساعت: 15:59